package com.wf.course.service.impl;


import java.util.HashMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.cloopen.rest.sdk.CCPRestSmsSDK;
import com.utils.page.PageBean;
import com.wf.course.dao.IMessageInfoMapper;
import com.wf.course.model.comm.MessageInfo;
import com.wf.course.service.IMessageInfoService;
import com.wf.course.web.Constants;

@Service
@Transactional
public class IMessageInfoServiceImpl implements IMessageInfoService {
	
	@Autowired
	private IMessageInfoMapper mapper;

	public void getMessageInfoList(PageBean<MessageInfo> pageBean) {
		// TODO Auto-generated method stub
		
		pageBean.setResults(mapper.getMessageInfoList(pageBean));
		pageBean.setTotalCount(mapper.getMessageInfoCount(pageBean));
		
	}

	@Override
	public void saveMessageInfo(MessageInfo messageInfo) {
		// TODO Auto-generated method stub
		
		mapper.saveMessageInfo(messageInfo);
		
	}

	@Override
	public void deleteMessageInfo(Integer id) {
		// TODO Auto-generated method stub
		mapper.deleteMessageInfo(id);
	}

	@Override
	public MessageInfo downLoadMessageInfo(Integer id) {
		// TODO Auto-generated method stub
		return mapper.downLoadMessageInfo(id);
	}

	@Override
	public Integer updateMessageInfo(MessageInfo messageInfo) {
		// TODO Auto-generated method stub
		return mapper.updateMessageInfo(messageInfo);
	}

	@Override
	public HashMap<String, Object> sendMsg(String telephone, String userId, String goodsName) {

		HashMap<String, Object> result = null;
		//初始化SDK
		CCPRestSmsSDK restAPI = new CCPRestSmsSDK();
		restAPI.init(Constants.YTX_SERVER, Constants.YTX_PORT);
		restAPI.setAccount(Constants.ACCOUNT_SID, Constants.ACCOUNT_TOKEN);
		restAPI.setAppId(Constants.APP_ID);
		result = restAPI.sendTemplateSMS(telephone,Constants.TEMP_ID ,new String[]{userId,goodsName});
		
			return result;
	}


	 

}
